import { _HttpClient } from '@delon/theme';
import { Injectable } from '@angular/core';
import { HttpParams, HttpHeaders } from '@angular/common/http';
import { LocalStorage } from '@core/local.storage';
import { ClearLoginService } from '@core/clearLogin.service';
import { environment } from '../../environments/environment';

const responseHeaders = new HttpHeaders().set('Content-Type', 'application/json;charset=UTF-8');

@Injectable({ providedIn: 'root' })

export class ControlApiService {

  constructor(
    private http: _HttpClient,
    public ls: LocalStorage,
    public clearLoginService: ClearLoginService
  ) { }

  // 同类报警案例
  listByBjlx(type) {
    const url = environment.apiBase + '/csmis/czjy/listByBjlx.jwt?bjlx=' + type;
    return this.http.get(url);
  }

  // 设备检修记录
  getWorkByDevName(id, name) {
    const url = environment.apiBase + '/csmis/prod/getWorkBystalhAndDevname.jwt?staId=' + id + '&devName=' + name + '&page=1';
    return this.http.get(url);
  }

  // 设备问题记录表
  getProbByDevname(name, id) {
    const url = environment.apiBase + '/csmis/pbvproblems/getProbByStalhAndDevname.jwt?devName=' + name + '&station=' + id + '&rows=10&page=1';
    return this.http.get(url);
  }

  // 设备历史信息故障
  listByCz(id, name) {
    const url = environment.apiBase + '/csmis/czjy/listByCz.jwt?cz=' + id + '&sbmc=' + name;
    return this.http.get(url);
  }

  // 车站设备名称
  getDevByStationType(id, typeid) {
    const url = environment.apiBase + '/csmis/publicTree/getDevByStationType.jwt?staid=' + id + '&typeid=' + typeid;
    return this.http.get(url);
  }

  // 报警类型
  getjcbjtype(id) {
    const url = environment.apiBase + '/csmis/publicTree/getjcbjtype.jwt?typeid=' + id;
    return this.http.get(url);
  }

  // 处置流程目录
  menuProcess() {
    const url = environment.apiBase + '/csmis/emProcess/getContent.jwt';
    return this.http.get(url);
  }

  // 线别
  getAllLines() {
    const url = environment.apiBase + '/csmis/getAllLines.jwt';
    return this.http.get(url);
  }

  // 系统和监测设备名互转
  getDevname(statid, devtype, devnameid, devtypename, devname, types, callback) {
    // type 1：指挥中心转监测，2：监测转指挥中心 3：指挥中心转履历 ，4：履历转指挥中心;type=2用A_DEVNAME，type=1用B_DEVNAME
    const params: any = {};
    statid ? params.czid = statid : params.czid = '';
    devtype ? params.lxid = devtype : params.lxid = '';
    devnameid ? params.mcid = devnameid : params.mcid = '';
    devtypename ? params.lx = devtypename : params.lx = '';
    devname ? params.mc = devname : params.mc = '';
    types ? params.type = types : params.type = '';
    this.http.post(environment.apiBase + '/csmis/tracetype/devName.jwt', params, { headers: responseHeaders }, { responseType: 'text' }).subscribe((res: any) => {
      if (callback) {
        callback(res);
      }
    });
  }

}
